%% US Public Debt and Safe Asset Market Power
%% Jason Choi, Rishabh Kirpalani, and Diego Perez
%% Sept 1, 2023

%% Plot transitions to Cournot equilibria

clear
clc
close all

% dynare cournot2
% dynare cournot3

load me1_me2
load me2_paths
load me1_me3
load me3_paths

plotT=200;

figure('position', [0, 0, 900, 900]);
subplot(4,2,1);
plot(1:plotT,[b_sme; 1/N_2*b_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[b_sme; 1/N_3*b_path_me3(1:plotT-1)],'red','LineWidth',2);
hold on;
plot(1:plotT,[b_sme; b_path_me2(1:plotT-1)],'b--','LineWidth',2);
hold on;
plot(1:plotT,[b_sme; b_path_me3(1:plotT-1)],'r--','LineWidth',2);
hold on;
plot(1:plotT,ones(1,plotT)*b_sme,'--black','LineWidth',1);
xlabel('Time');
title('Safe assets');
xlim([0 plotT]);
legend('N=2 (US)','N=3 (US)','N=2 (Total)','N=3 (Total)');

subplot(4,2,2);
plot(1:plotT,[rk_sme-ddelta_rw-rb_sme; rk_path_me2(1:plotT-1)-ddelta_rw-rb_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[rk_sme-ddelta_rw-rb_sme; rk_path_me3(1:plotT-1)-ddelta_rw-rb_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('Convenience yield')
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,3);
plot(1:plotT,[cus_sme; cus_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[cus_sme; cus_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('US Consumption');
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,4);
plot(1:plotT,[crw_sme; crw_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[crw_sme; crw_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('RoW Consumption');
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,5);
plot(1:plotT,[rk_sme; rk_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[rk_sme; rk_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('US Capital Interest Rate');
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,6);
plot(1:plotT,[rkstar_sme; rkstar_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[rkstar_sme; rkstar_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('RoW Capital Interest Rate');
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,7);
plot(1:plotT,[k_sme; k_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[k_sme; k_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('US Capital');
xlim([0 plotT]);
legend('N=2','N=3');

subplot(4,2,8);
plot(1:plotT,[kstar_sme; kstar_path_me2(1:plotT-1)],'blue','LineWidth',2);
hold on;
plot(1:plotT,[kstar_sme; kstar_path_me3(1:plotT-1)],'red','LineWidth',2);
xlabel('Time');
title('RoW Capital');
xlim([0 plotT]);
legend('N=2','N=3');